package com.wuliupai.delivery.wuliupaidelivery.activity;

import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.wuliupai.delivery.wuliupaidelivery.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;

/**
 * Descriptions：WebView
 * <p>
 * Author：ChenME
 * Date：2016/12/21
 * Email：ibelieve1210@163.com
 */
@EActivity(R.layout.activity_common_webview)
public class CommonWebViewActivity extends AppBaseActivity {

    @ViewById(R.id.webView)
    WebView webView;

    @Extra("whichPage")
    int whichPage;
    @Extra("pageUrl")
    String pageUrl;

    public static final int Page_PriceExplain = 0xf171;//价格说明页面

    @AfterViews
    void onPageStart() {
        switch (whichPage) {
            case Page_PriceExplain://价格说明页面
                pageUrl = "http://www.paigekuaiyun.com/page/applink/price.html";
                setDefaultTitle(this,"价格说明");
                break;
        }

        initWebView();
        webView.loadUrl(pageUrl);
    }

    /**
     * 初始化WebView
     */
    private void initWebView( ) {
        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient() {
            //            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
//                handler.proceed(); //接受证书
//            }
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return true;//阻止手机上其他的浏览器
            }


        });

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true); //持JavaScript脚本
        webSettings.setAllowFileAccess(true); //启用WebView访问文件数据
        webSettings.setBuiltInZoomControls(true); //支持缩放
        webSettings.setDisplayZoomControls(false); //隐藏缩放按钮
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setDefaultTextEncodingName("UTF-8");
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setDomStorageEnabled(true);
    }



    @Override
    public void onBackPressed() {
        super.onBackPressed();
        animUtils.leftOutAnimation(this);
    }
}